package com.example.demo.service.impl;

import java.util.List;

/**
 * 示例类：包含为了演示CPD重复检测而故意编写的重复代码。
 */
public class OrderRiskEvaluator {

    public String buildRiskReport(String orderId, int failedPaymentCount, List<String> riskTags) {
        StringBuilder builder = new StringBuilder();
        builder.append("Order[").append(orderId).append("] Risk Report\n");
        builder.append("Failed payments: ").append(failedPaymentCount).append("\n");

        if (riskTags == null || riskTags.isEmpty()) {
            builder.append("Risk tags: NONE\n");
        } else {
            builder.append("Risk tags: ");
            for (int i = 0; i < riskTags.size(); i++) {
                builder.append(riskTags.get(i));
                if (i < riskTags.size() - 1) {
                    builder.append(", ");
                }
            }
            builder.append("\n");
        }

        builder.append("Severity: ");
        if (failedPaymentCount > 5 || (riskTags != null && riskTags.contains("BLACKLIST"))) {
            builder.append("HIGH");
        } else if (failedPaymentCount > 2) {
            builder.append("MEDIUM");
        } else {
            builder.append("LOW");
        }

        builder.append("\nAdvice: ");
        if (failedPaymentCount > 5) {
            builder.append("Freeze account immediately.");
        } else if (failedPaymentCount > 2) {
            builder.append("Require manual review.");
        } else {
            builder.append("Continue monitoring.");
        }

        return builder.toString();
    }
}
